#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    vector<string> ret;
    void dfs(string str, int l, int r)
    {
        if (l == 0 && r == 0)
        {
            ret.push_back(str);
        }
        else if (l > r || l < 0)
        {
            return;
        }
        dfs(str + "(", l - 1, r);
        dfs(str + ")", l, r - 1);
    }
    vector<string> generateParenthesis(int n)
    {
        dfs("", n, n);
        return ret;
    }
};